/*
 * 文件名：HttpUtil.java
 * 版权：Copyright 2006-2011 AsiaInfo Tech. Co. Ltd. All Rights Reserved. 
 * 描述： HttpUtil.java
 * 修改人：齐鹏飞
 * 修改时间：2011-8-12
 * 修改内容：新增
 */
package com.fengxing.ams.pub.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.fengxing.ams.pub.constants.Constants;

/**
 * Http工具类
 * <p>
 * <p>
 * 
 * <pre>
 * </pre>
 * 
 * @author 齐鹏飞
 * @version CTMS V100R001 2011-8-12
 * @since CTMS V100R001C01
 */
public class HttpUtil
{

    /**
     * 
     * 获取Http上送的header头信息，并且将客户端IP地址 以client_ip为键放入 所有的键都转化为小写
     * 
     * @param request
     *            HttpServletRequest
     * @return Map Http的头信息，以键值对的形式返回
     */
    @SuppressWarnings("unchecked")
    public static Map<String, String> getRequestHeaders(
            HttpServletRequest request)
    {
        Map<String, String> headers = new HashMap<String, String>();

        String headerName = null;

        for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();)
        {
            headerName = (String) e.nextElement();

            headers.put(StringUtils.lowerCase(headerName).trim(), request
                    .getHeader(headerName));
        }

        String clientIP = request.getRemoteAddr();

        headers.put(Constants.CLIENT_IP, clientIP);

        return headers;
    }

}
